package com.eco.fanliapp.common.base;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import com.alibaba.fastjson.JSONObject;
import com.eco.fanliapp.entity.AppUser;
/**
 * @ProjectName: fanliapp
 * @Package: com.eco.fanliapp.common.base
 * @ClassName: AuthController
 * @Author: LC
 * @Description:
 * @Date: 2019/11/28 15:13
 * @Version: 4.2.2
 */
public class AuthController {

    private static final Logger logger = LoggerFactory.getLogger(AuthController.class);

    public AppUser getAppUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        try {
        	AppUser appUser = JSONObject.parseObject((String)authentication.getPrincipal(),AppUser.class);
            return appUser;
        } catch (Exception e) {
            logger.info("获取用户登录信息错误-error=" + e.getMessage());
        }
        return null;
    }

}
